package agents.curatoragentbehaviours;

import java.io.IOException;
import java.util.HashMap;
import resource.Artifact;
import agents.CuratorAgent;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.UnreadableException;

public class SendDetailedInfoOfArtifactsBehaviour extends OneShotBehaviour{
	private CuratorAgent agent;
	private ACLMessage msg;

	public SendDetailedInfoOfArtifactsBehaviour(CuratorAgent agent, ACLMessage msg){
		super(agent);
		this.agent = agent;
		this.msg = msg;
	}
	
	@Override
	public void action() {
		try {
			String[] content = (String[]) msg.getContentObject();
			
			String[] detailedArtifactDescriptions = new String[content.length];
			HashMap<String, Artifact> artifacts = agent.getArtifacts();
			
			for (int i = 0; i < content.length; i++){
				Artifact art = artifacts.get(content[i]);
				detailedArtifactDescriptions[i] = 
					"Name: " + art.getName() + "\n" +
					"Genre: " + art.getGenre() + "\n" +
					"Description: " + art.getDescription() + "\n" +
					"Year of Creation: " + art.getYear();	
			}
			
			ACLMessage msg2 = new ACLMessage(ACLMessage.INFORM);
			msg2.addReceiver(msg.getSender());
			msg2.setSender(agent.getAID());
			msg2.setContentObject(detailedArtifactDescriptions);
			agent.send(msg2);
		} catch (UnreadableException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
